package com.hqyj.module.holiday.dao;

import com.hqyj.module.clock.pojo.SearchBean;
import com.hqyj.module.holiday.pojo.Holiday;
import com.hqyj.module.holiday.pojo.MyUserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lap
 * @version 1.0
 * @date 2021/10/8 10:35
 */

@Repository
public interface MyHolidayDao {

    @Insert("INSERT into holiday(user_id,user_name,thing,start_time,end_time,ho_type) VALUES(#{userId},#{userName},#{thing},#{startTime},#{endTime},#{hoType})")
    Integer insertHoliday(Holiday holiday);

    @Select("<script>"
            + "select * from holiday"
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " and (city_name like '%${keyword}%' or "
            + " local_city_name like '%${keyword}%') "
            + "</if>"
            + "and verify_id is NOT null and ho_type= 'thing'"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Holiday> getCitiesBySearchBean(SearchBean searchBean);

    @Select("<script>"
            + "select * from holiday"
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " and (city_name like '%${keyword}%' or "
            + " local_city_name like '%${keyword}%') "
            + "</if>"
            + "and verify_id is NOT null and ho_type= 'business'"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Holiday> getBusinessBySearchBean(SearchBean searchBean);

    @Select("<script>"
            + "select * from holiday"
            + "<where> "
            + "verify_id is null and ho_type= 'business' and user_name = #{keyword}"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Holiday> getBusinessBySearchBeanApp(SearchBean searchBean);

    @Select("<script>"
            + "select * from holiday"
            + "<where> "
            + "verify_id is null and ho_type= 'thing' and user_name = #{keyword}"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Holiday> getThingBySearchBeanApp(SearchBean searchBean);


    @Select("<script>"
            + "select * from holiday"
            + "<where> "
            + "verify_id is null"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Holiday> getHolidayBySearchBeanApp(SearchBean searchBean);

    @Select("select * from holiday \n" +
            "where verify_id is null\n" +
            "and user_id LIKE #{lineId}")
    List<Holiday> getHolidays(String likeId);


    @Select("select user_id,user_name,role from user_info where user_id=#{userId}")
    MyUserInfo getUserInfo(Integer userId);
}
